<template>
    <view>
        <view>
            <ant-form-input label="中文姓名" name="account" required :position="position" ref="handleRef" />

            <form-picker label="证件类型" arrow name="fruit" :options="fruitList" ref="handleRef" />

            <ant-form-input label="证件号码" name="address" :position="position" ref="handleRef" />
        </view>

        <view class="disi">
            <ant-button type="primary" onTap="handleTap">保存</ant-button>
        </view>
    </view>
</template>

<script>

export default {
    components: {
       
    },
    data() {
        return {
            fruitList: ['居民身份证', '外籍', '华侨'],
            toastShow: false,
            position: ''
        };
    },
    onLoad() {
        this.form = new Form();
    },
    methods: {
        handleRef(ref) {
            this.form.addItem(ref);
        },

        reset() {
            this.form.reset();
        },

        showToast() {
            this.setData({
                toastShow: true
            });
        },

        handleCloseToast() {
            this.setData({
                toastShow: false
            });
        },

        async handleTap() {
            const values = await this.form.submit();
            console.log(values);
            uni.getStorage({
                key: 'openId',
                success: (res) => {
                    const openId = res.data.openId;
                    console.log(values.address);
                    console.log(openId);
                    console.log(values.account);
                    uni.request({
                        url: 'http://localhost:5657/updateGoPeople',
                        method: 'POST',
                        data: {
                            openID: res.data.openId,
                            peopleName: values.account,
                            peopleCard: values.address
                        },
                        headers: {
                            'content-type': 'application/json'
                        },
                        dataType: 'json',
                        success: function (res) {
                            uni.alert({
                                title: '修改成功'
                            });
                            uni.switchTab({
                                url: '/pages/myPage/myPage'
                            });
                        },
                        fail: function (error) {
                            console.error('fail: ', JSON.stringify(error));
                        }
                    });
                }
            });
        }
    }
};
</script>
<style>
.buttons {
    background: #ffffff;
    padding: 12px 12px 48px 12px;
}
.disi {
    height: 100px;
    width: 90%;
    bottom: 0;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    position: absolute;
    left: 20px;
    right: 10px;
}

.diwu {
    height: 100px;
    width: 90%;
    bottom: 0;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    position: absolute;
    left: 20px;
    right: 10px;
}

</style>
